{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.1 The MultiIndex Object"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('8809 Flair Square', 'Toddside', 'IL', '37206')"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "address = (\"8809 Flair Square\", \"Toddside\", \"IL\", \"37206\")\n",
    "address"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "addresses = [\n",
    "    (\"8809 Flair Square\", \"Toddside\", \"IL\", \"37206\"),\n",
    "    (\"9901 Austin Street\", \"Toddside\", \"IL\", \"37206\"),\n",
    "    (\"905 Hogan Quarter\", \"Franklin\", \"IL\", \"37206\"),\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MultiIndex([( '8809 Flair Square', 'Toddside', 'IL', '37206'),\n",
       "            ('9901 Austin Street', 'Toddside', 'IL', '37206'),\n",
       "            ( '905 Hogan Quarter', 'Franklin', 'IL', '37206')],\n",
       "           )"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "pd.MultiIndex.from_tuples(addresses)\n",
    "pd.MultiIndex.from_tuples(tuples = addresses)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MultiIndex([( '8809 Flair Square', 'Toddside', 'IL', '37206'),\n",
       "            ('9901 Austin Street', 'Toddside', 'IL', '37206'),\n",
       "            ( '905 Hogan Quarter', 'Franklin', 'IL', '37206')],\n",
       "           names=['Street', 'City', 'State', 'Zip'])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "row_index = pd.MultiIndex.from_tuples(\n",
    "    tuples = addresses,\n",
    "    names = [\"Street\", \"City\", \"State\", \"Zip\"]\n",
    ")\n",
    "\n",
    "row_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Schools</th>\n",
       "      <th>Cost of Living</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Street</th>\n",
       "      <th>City</th>\n",
       "      <th>State</th>\n",
       "      <th>Zip</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>8809 Flair Square</th>\n",
       "      <th>Toddside</th>\n",
       "      <th>IL</th>\n",
       "      <th>37206</th>\n",
       "      <td>A</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9901 Austin Street</th>\n",
       "      <th>Toddside</th>\n",
       "      <th>IL</th>\n",
       "      <th>37206</th>\n",
       "      <td>C+</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>905 Hogan Quarter</th>\n",
       "      <th>Franklin</th>\n",
       "      <th>IL</th>\n",
       "      <th>37206</th>\n",
       "      <td>D-</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        Schools Cost of Living\n",
       "Street             City     State Zip                         \n",
       "8809 Flair Square  Toddside IL    37206       A             B+\n",
       "9901 Austin Street Toddside IL    37206      C+              C\n",
       "905 Hogan Quarter  Franklin IL    37206      D-              A"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = [\n",
    "    [\"A\", \"B+\"],\n",
    "    [\"C+\", \"C\"],\n",
    "    [\"D-\", \"A\"],\n",
    "]\n",
    "\n",
    "columns = [\"Schools\", \"Cost of Living\"]\n",
    "\n",
    "area_grades = pd.DataFrame(\n",
    "    data = data, index = row_index, columns = columns\n",
    ")\n",
    "\n",
    "area_grades"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Schools', 'Cost of Living'], dtype='object')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "area_grades.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MultiIndex([( 'Culture', 'Restaurants'),\n",
       "            ( 'Culture',     'Museums'),\n",
       "            ('Services',      'Police'),\n",
       "            ('Services',     'Schools')],\n",
       "           )"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "column_index = pd.MultiIndex.from_tuples([\n",
    "    (\"Culture\", \"Restaurants\"),\n",
    "    (\"Culture\", \"Museums\"),\n",
    "    (\"Services\", \"Police\"),\n",
    "    (\"Services\", \"Schools\"),\n",
    "])\n",
    "\n",
    "column_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = [\n",
    "    [\"C-\", \"B+\", \"B-\", \"A\"],\n",
    "    [\"D+\", \"C\", \"A\", \"C+\"],\n",
    "    [\"A-\", \"A\", \"D+\", \"F\"], \n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Street</th>\n",
       "      <th>City</th>\n",
       "      <th>State</th>\n",
       "      <th>Zip</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>8809 Flair Square</th>\n",
       "      <th>Toddside</th>\n",
       "      <th>IL</th>\n",
       "      <th>37206</th>\n",
       "      <td>C-</td>\n",
       "      <td>B+</td>\n",
       "      <td>B-</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9901 Austin Street</th>\n",
       "      <th>Toddside</th>\n",
       "      <th>IL</th>\n",
       "      <th>37206</th>\n",
       "      <td>D+</td>\n",
       "      <td>C</td>\n",
       "      <td>A</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>905 Hogan Quarter</th>\n",
       "      <th>Franklin</th>\n",
       "      <th>IL</th>\n",
       "      <th>37206</th>\n",
       "      <td>A-</td>\n",
       "      <td>A</td>\n",
       "      <td>D+</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            Culture         Services        \n",
       "                                        Restaurants Museums   Police Schools\n",
       "Street             City     State Zip                                       \n",
       "8809 Flair Square  Toddside IL    37206          C-      B+       B-       A\n",
       "9901 Austin Street Toddside IL    37206          D+       C        A      C+\n",
       "905 Hogan Quarter  Franklin IL    37206          A-       A       D+       F"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(\n",
    "    data = data, index = row_index, columns = column_index\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.2 MultiIndex DataFrames"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>Unnamed: 1</th>\n",
       "      <th>Unnamed: 2</th>\n",
       "      <th>Culture</th>\n",
       "      <th>Culture.1</th>\n",
       "      <th>Services</th>\n",
       "      <th>Services.1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Restaurants</td>\n",
       "      <td>Museums</td>\n",
       "      <td>Police</td>\n",
       "      <td>Schools</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>State</td>\n",
       "      <td>City</td>\n",
       "      <td>Street</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MO</td>\n",
       "      <td>Fisherborough</td>\n",
       "      <td>244 Tracy View</td>\n",
       "      <td>C+</td>\n",
       "      <td>F</td>\n",
       "      <td>D-</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>SD</td>\n",
       "      <td>Port Curtisville</td>\n",
       "      <td>446 Cynthia Inlet</td>\n",
       "      <td>C-</td>\n",
       "      <td>B</td>\n",
       "      <td>B</td>\n",
       "      <td>D+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>WV</td>\n",
       "      <td>Jimenezview</td>\n",
       "      <td>432 John Common</td>\n",
       "      <td>A</td>\n",
       "      <td>A+</td>\n",
       "      <td>F</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Unnamed: 0        Unnamed: 1         Unnamed: 2      Culture Culture.1  \\\n",
       "0        NaN               NaN                NaN  Restaurants   Museums   \n",
       "1      State              City             Street          NaN       NaN   \n",
       "2         MO     Fisherborough     244 Tracy View           C+         F   \n",
       "3         SD  Port Curtisville  446 Cynthia Inlet           C-         B   \n",
       "4         WV       Jimenezview    432 John Common            A        A+   \n",
       "\n",
       "  Services Services.1  \n",
       "0   Police    Schools  \n",
       "1      NaN        NaN  \n",
       "2       D-         A+  \n",
       "3        B         D+  \n",
       "4        F          B  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods = pd.read_csv(\"neighborhoods.csv\")\n",
    "neighborhoods.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Culture</th>\n",
       "      <th>Culture.1</th>\n",
       "      <th>Services</th>\n",
       "      <th>Services.1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>NaN</th>\n",
       "      <th>NaN</th>\n",
       "      <th>NaN</th>\n",
       "      <td>Restaurants</td>\n",
       "      <td>Museums</td>\n",
       "      <td>Police</td>\n",
       "      <td>Schools</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MO</th>\n",
       "      <th>Fisherborough</th>\n",
       "      <th>244 Tracy View</th>\n",
       "      <td>C+</td>\n",
       "      <td>F</td>\n",
       "      <td>D-</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SD</th>\n",
       "      <th>Port Curtisville</th>\n",
       "      <th>446 Cynthia Inlet</th>\n",
       "      <td>C-</td>\n",
       "      <td>B</td>\n",
       "      <td>B</td>\n",
       "      <td>D+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WV</th>\n",
       "      <th>Jimenezview</th>\n",
       "      <th>432 John Common</th>\n",
       "      <td>A</td>\n",
       "      <td>A+</td>\n",
       "      <td>F</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                              Culture Culture.1 Services  \\\n",
       "NaN   NaN              NaN                Restaurants   Museums   Police   \n",
       "State City             Street                     NaN       NaN      NaN   \n",
       "MO    Fisherborough    244 Tracy View              C+         F       D-   \n",
       "SD    Port Curtisville 446 Cynthia Inlet           C-         B        B   \n",
       "WV    Jimenezview      432 John Common              A        A+        F   \n",
       "\n",
       "                                         Services.1  \n",
       "NaN   NaN              NaN                  Schools  \n",
       "State City             Street                   NaN  \n",
       "MO    Fisherborough    244 Tracy View            A+  \n",
       "SD    Port Curtisville 446 Cynthia Inlet         D+  \n",
       "WV    Jimenezview      432 John Common            B  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods = pd.read_csv(\n",
    "    \"neighborhoods.csv\",\n",
    "    index_col = [0, 1, 2]\n",
    ")\n",
    "\n",
    "neighborhoods.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>MO</th>\n",
       "      <th>Fisherborough</th>\n",
       "      <th>244 Tracy View</th>\n",
       "      <td>C+</td>\n",
       "      <td>F</td>\n",
       "      <td>D-</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SD</th>\n",
       "      <th>Port Curtisville</th>\n",
       "      <th>446 Cynthia Inlet</th>\n",
       "      <td>C-</td>\n",
       "      <td>B</td>\n",
       "      <td>B</td>\n",
       "      <td>D+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WV</th>\n",
       "      <th>Jimenezview</th>\n",
       "      <th>432 John Common</th>\n",
       "      <td>A</td>\n",
       "      <td>A+</td>\n",
       "      <td>F</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AK</th>\n",
       "      <th>Stevenshire</th>\n",
       "      <th>238 Andrew Rue</th>\n",
       "      <td>D-</td>\n",
       "      <td>A</td>\n",
       "      <td>A-</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ND</th>\n",
       "      <th>New Joshuaport</th>\n",
       "      <th>877 Walter Neck</th>\n",
       "      <td>D+</td>\n",
       "      <td>C-</td>\n",
       "      <td>B</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                             Culture         Services        \n",
       "                                         Restaurants Museums   Police Schools\n",
       "State City             Street                                                \n",
       "MO    Fisherborough    244 Tracy View             C+       F       D-      A+\n",
       "SD    Port Curtisville 446 Cynthia Inlet          C-       B        B      D+\n",
       "WV    Jimenezview      432 John Common             A      A+        F       B\n",
       "AK    Stevenshire      238 Andrew Rue             D-       A       A-      A-\n",
       "ND    New Joshuaport   877 Walter Neck            D+      C-        B       B"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods = pd.read_csv(\n",
    "    \"neighborhoods.csv\",\n",
    "    index_col = [0, 1, 2],\n",
    "    header = [0, 1]\n",
    ")\n",
    "\n",
    "neighborhoods.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "MultiIndex: 251 entries, ('MO', 'Fisherborough', '244 Tracy View') to ('NE', 'South Kennethmouth', '346 Wallace Pass')\n",
      "Data columns (total 4 columns):\n",
      " #   Column                  Non-Null Count  Dtype \n",
      "---  ------                  --------------  ----- \n",
      " 0   (Culture, Restaurants)  251 non-null    object\n",
      " 1   (Culture, Museums)      251 non-null    object\n",
      " 2   (Services, Police)      251 non-null    object\n",
      " 3   (Services, Schools)     251 non-null    object\n",
      "dtypes: object(4)\n",
      "memory usage: 27.2+ KB\n"
     ]
    }
   ],
   "source": [
    "neighborhoods.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MultiIndex([('MO',      'Fisherborough',        '244 Tracy View'),\n",
       "            ('SD',   'Port Curtisville',     '446 Cynthia Inlet'),\n",
       "            ('WV',        'Jimenezview',       '432 John Common'),\n",
       "            ('AK',        'Stevenshire',        '238 Andrew Rue'),\n",
       "            ('ND',     'New Joshuaport',       '877 Walter Neck'),\n",
       "            ('ID',         'Wellsville',   '696 Weber Stravenue'),\n",
       "            ('TN',          'Jodiburgh',    '285 Justin Corners'),\n",
       "            ('DC',   'Lake Christopher',   '607 Montoya Harbors'),\n",
       "            ('OH',          'Port Mike',      '041 Michael Neck'),\n",
       "            ('ND',         'Hardyburgh', '550 Gilmore Mountains'),\n",
       "            ...\n",
       "            ('AK',          'Scottstad',      '114 Jones Garden'),\n",
       "            ('IA',    'Port Willieport',  '320 Jennifer Mission'),\n",
       "            ('ME',         'Port Linda',        '692 Hill Glens'),\n",
       "            ('KS',         'Kaylamouth',       '483 Freeman Via'),\n",
       "            ('WA',     'Port Shawnfort',    '691 Winters Bridge'),\n",
       "            ('MI',      'North Matthew',      '055 Clayton Isle'),\n",
       "            ('MT',            'Chadton',     '601 Richards Road'),\n",
       "            ('SC',          'Diazmouth',     '385 Robin Harbors'),\n",
       "            ('VA',         'Laurentown',     '255 Gonzalez Land'),\n",
       "            ('NE', 'South Kennethmouth',      '346 Wallace Pass')],\n",
       "           names=['State', 'City', 'Street'], length=251)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MultiIndex([( 'Culture', 'Restaurants'),\n",
       "            ( 'Culture',     'Museums'),\n",
       "            ('Services',      'Police'),\n",
       "            ('Services',     'Schools')],\n",
       "           )"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "FrozenList(['State', 'City', 'Street'])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.index.names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Fisherborough', 'Port Curtisville', 'Jimenezview', 'Stevenshire',\n",
       "       'New Joshuaport', 'Wellsville', 'Jodiburgh', 'Lake Christopher',\n",
       "       'Port Mike', 'Hardyburgh',\n",
       "       ...\n",
       "       'Scottstad', 'Port Willieport', 'Port Linda', 'Kaylamouth',\n",
       "       'Port Shawnfort', 'North Matthew', 'Chadton', 'Diazmouth', 'Laurentown',\n",
       "       'South Kennethmouth'],\n",
       "      dtype='object', name='City', length=251)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "neighborhoods.index.get_level_values(1)\n",
    "neighborhoods.index.get_level_values(\"City\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "FrozenList([None, None])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.columns.names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "FrozenList(['Category', 'Subcategory'])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.columns.names = [\"Category\", \"Subcategory\"]\n",
    "neighborhoods.columns.names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>MO</th>\n",
       "      <th>Fisherborough</th>\n",
       "      <th>244 Tracy View</th>\n",
       "      <td>C+</td>\n",
       "      <td>F</td>\n",
       "      <td>D-</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SD</th>\n",
       "      <th>Port Curtisville</th>\n",
       "      <th>446 Cynthia Inlet</th>\n",
       "      <td>C-</td>\n",
       "      <td>B</td>\n",
       "      <td>B</td>\n",
       "      <td>D+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WV</th>\n",
       "      <th>Jimenezview</th>\n",
       "      <th>432 John Common</th>\n",
       "      <td>A</td>\n",
       "      <td>A+</td>\n",
       "      <td>F</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                     Culture         Services        \n",
       "Subcategory                              Restaurants Museums   Police Schools\n",
       "State City             Street                                                \n",
       "MO    Fisherborough    244 Tracy View             C+       F       D-      A+\n",
       "SD    Port Curtisville 446 Cynthia Inlet          C-       B        B      D+\n",
       "WV    Jimenezview      432 John Common             A      A+        F       B"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Culture', 'Culture', 'Services', 'Services'], dtype='object', name='Category')"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "neighborhoods.columns.get_level_values(0)\n",
    "neighborhoods.columns.get_level_values(\"Category\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>MO</th>\n",
       "      <th>Fisherborough</th>\n",
       "      <th>244 Tracy View</th>\n",
       "      <td>C+</td>\n",
       "      <td>F</td>\n",
       "      <td>D-</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                               Culture         Services        \n",
       "Subcategory                        Restaurants Museums   Police Schools\n",
       "State City          Street                                             \n",
       "MO    Fisherborough 244 Tracy View          C+       F       D-      A+"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Category  Subcategory\n",
       "Culture   Restaurants    13\n",
       "          Museums        13\n",
       "Services  Police         13\n",
       "          Schools        13\n",
       "dtype: int64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.nunique()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.3 Sorting a MultiIndex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">AK</th>\n",
       "      <th>Rowlandchester</th>\n",
       "      <th>386 Rebecca Cove</th>\n",
       "      <td>C-</td>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Scottstad</th>\n",
       "      <th>082 Leblanc Freeway</th>\n",
       "      <td>D</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114 Jones Garden</th>\n",
       "      <td>D-</td>\n",
       "      <td>D-</td>\n",
       "      <td>D</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stevenshire</th>\n",
       "      <th>238 Andrew Rue</th>\n",
       "      <td>D-</td>\n",
       "      <td>A</td>\n",
       "      <td>A-</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AL</th>\n",
       "      <th>Clarkland</th>\n",
       "      <th>430 Douglas Mission</th>\n",
       "      <td>A</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">WY</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Lake Nicole</th>\n",
       "      <th>754 Weaver Turnpike</th>\n",
       "      <td>B</td>\n",
       "      <td>D-</td>\n",
       "      <td>B</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>933 Jennifer Burg</th>\n",
       "      <td>C</td>\n",
       "      <td>A+</td>\n",
       "      <td>A-</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Martintown</th>\n",
       "      <th>013 Bell Mills</th>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>A-</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Port Jason</th>\n",
       "      <th>624 Faulkner Orchard</th>\n",
       "      <td>A-</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Reneeshire</th>\n",
       "      <th>717 Patel Square</th>\n",
       "      <td>B</td>\n",
       "      <td>B+</td>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>251 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                      Culture         Services        \n",
       "Subcategory                               Restaurants Museums   Police Schools\n",
       "State City           Street                                                   \n",
       "AK    Rowlandchester 386 Rebecca Cove              C-      A-       A+       C\n",
       "      Scottstad      082 Leblanc Freeway            D      C-        D      B+\n",
       "                     114 Jones Garden              D-      D-        D       D\n",
       "      Stevenshire    238 Andrew Rue                D-       A       A-      A-\n",
       "AL    Clarkland      430 Douglas Mission            A       F       C+      B+\n",
       "...                                               ...     ...      ...     ...\n",
       "WY    Lake Nicole    754 Weaver Turnpike            B      D-        B       D\n",
       "                     933 Jennifer Burg              C      A+       A-       C\n",
       "      Martintown     013 Bell Mills                C-       D       A-      B-\n",
       "      Port Jason     624 Faulkner Orchard          A-       F       C+      C+\n",
       "      Reneeshire     717 Patel Square               B      B+        D       A\n",
       "\n",
       "[251 rows x 4 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">WY</th>\n",
       "      <th>Reneeshire</th>\n",
       "      <th>717 Patel Square</th>\n",
       "      <td>B</td>\n",
       "      <td>B+</td>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Port Jason</th>\n",
       "      <th>624 Faulkner Orchard</th>\n",
       "      <td>A-</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Martintown</th>\n",
       "      <th>013 Bell Mills</th>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>A-</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Lake Nicole</th>\n",
       "      <th>933 Jennifer Burg</th>\n",
       "      <td>C</td>\n",
       "      <td>A+</td>\n",
       "      <td>A-</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>754 Weaver Turnpike</th>\n",
       "      <td>B</td>\n",
       "      <td>D-</td>\n",
       "      <td>B</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                   Culture         Services        \n",
       "Subcategory                            Restaurants Museums   Police Schools\n",
       "State City        Street                                                   \n",
       "WY    Reneeshire  717 Patel Square               B      B+        D       A\n",
       "      Port Jason  624 Faulkner Orchard          A-       F       C+      C+\n",
       "      Martintown  013 Bell Mills                C-       D       A-      B-\n",
       "      Lake Nicole 933 Jennifer Burg              C      A+       A-       C\n",
       "                  754 Weaver Turnpike            B      D-        B       D"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.sort_index(ascending = False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">AK</th>\n",
       "      <th>Stevenshire</th>\n",
       "      <th>238 Andrew Rue</th>\n",
       "      <td>D-</td>\n",
       "      <td>A</td>\n",
       "      <td>A-</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Scottstad</th>\n",
       "      <th>082 Leblanc Freeway</th>\n",
       "      <td>D</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114 Jones Garden</th>\n",
       "      <td>D-</td>\n",
       "      <td>D-</td>\n",
       "      <td>D</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rowlandchester</th>\n",
       "      <th>386 Rebecca Cove</th>\n",
       "      <td>C-</td>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AL</th>\n",
       "      <th>Vegaside</th>\n",
       "      <th>191 Mindy Meadows</th>\n",
       "      <td>B+</td>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>D+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                     Culture         Services        \n",
       "Subcategory                              Restaurants Museums   Police Schools\n",
       "State City           Street                                                  \n",
       "AK    Stevenshire    238 Andrew Rue               D-       A       A-      A-\n",
       "      Scottstad      082 Leblanc Freeway           D      C-        D      B+\n",
       "                     114 Jones Garden             D-      D-        D       D\n",
       "      Rowlandchester 386 Rebecca Cove             C-      A-       A+       C\n",
       "AL    Vegaside       191 Mindy Meadows            B+      A-       A+      D+"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.sort_index(ascending = [True, False, True]).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AR</th>\n",
       "      <th>Allisonland</th>\n",
       "      <th>124 Diaz Brooks</th>\n",
       "      <td>C-</td>\n",
       "      <td>A+</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GA</th>\n",
       "      <th>Amyburgh</th>\n",
       "      <th>941 Brian Expressway</th>\n",
       "      <td>B</td>\n",
       "      <td>B</td>\n",
       "      <td>D-</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>IA</th>\n",
       "      <th>Amyburgh</th>\n",
       "      <th>163 Heather Neck</th>\n",
       "      <td>F</td>\n",
       "      <td>D</td>\n",
       "      <td>A+</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th>Andrewshire</th>\n",
       "      <th>952 Ellis Drive</th>\n",
       "      <td>C+</td>\n",
       "      <td>A-</td>\n",
       "      <td>C+</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UT</th>\n",
       "      <th>Baileyfort</th>\n",
       "      <th>919 Stewart Hills</th>\n",
       "      <td>D+</td>\n",
       "      <td>C+</td>\n",
       "      <td>A</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>NC</th>\n",
       "      <th>West Scott</th>\n",
       "      <th>348 Jack Branch</th>\n",
       "      <td>A-</td>\n",
       "      <td>D-</td>\n",
       "      <td>A-</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SD</th>\n",
       "      <th>West Scott</th>\n",
       "      <th>139 Hardy Vista</th>\n",
       "      <td>C+</td>\n",
       "      <td>A-</td>\n",
       "      <td>D+</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>IN</th>\n",
       "      <th>Wilsonborough</th>\n",
       "      <th>066 Carr Road</th>\n",
       "      <td>A+</td>\n",
       "      <td>C-</td>\n",
       "      <td>B</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>NC</th>\n",
       "      <th>Wilsonshire</th>\n",
       "      <th>871 Christopher Vista</th>\n",
       "      <td>B+</td>\n",
       "      <td>B</td>\n",
       "      <td>D+</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>NV</th>\n",
       "      <th>Wilsonshire</th>\n",
       "      <th>542 Jessica Stream</th>\n",
       "      <td>A</td>\n",
       "      <td>A+</td>\n",
       "      <td>C-</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>251 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                      Culture         Services        \n",
       "Subcategory                               Restaurants Museums   Police Schools\n",
       "State City          Street                                                    \n",
       "AR    Allisonland   124 Diaz Brooks                C-      A+        F      C+\n",
       "GA    Amyburgh      941 Brian Expressway            B       B       D-      C+\n",
       "IA    Amyburgh      163 Heather Neck                F       D       A+      A-\n",
       "ID    Andrewshire   952 Ellis Drive                C+      A-       C+       A\n",
       "UT    Baileyfort    919 Stewart Hills              D+      C+        A       C\n",
       "...                                               ...     ...      ...     ...\n",
       "NC    West Scott    348 Jack Branch                A-      D-       A-       A\n",
       "SD    West Scott    139 Hardy Vista                C+      A-       D+      B-\n",
       "IN    Wilsonborough 066 Carr Road                  A+      C-        B       F\n",
       "NC    Wilsonshire   871 Christopher Vista          B+       B       D+       F\n",
       "NV    Wilsonshire   542 Jessica Stream              A      A+       C-      C+\n",
       "\n",
       "[251 rows x 4 columns]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "neighborhoods.sort_index(level = 1)\n",
    "neighborhoods.sort_index(level = \"City\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AR</th>\n",
       "      <th>Allisonland</th>\n",
       "      <th>124 Diaz Brooks</th>\n",
       "      <td>C-</td>\n",
       "      <td>A+</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>IA</th>\n",
       "      <th>Amyburgh</th>\n",
       "      <th>163 Heather Neck</th>\n",
       "      <td>F</td>\n",
       "      <td>D</td>\n",
       "      <td>A+</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GA</th>\n",
       "      <th>Amyburgh</th>\n",
       "      <th>941 Brian Expressway</th>\n",
       "      <td>B</td>\n",
       "      <td>B</td>\n",
       "      <td>D-</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th>Andrewshire</th>\n",
       "      <th>952 Ellis Drive</th>\n",
       "      <td>C+</td>\n",
       "      <td>A-</td>\n",
       "      <td>C+</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>VT</th>\n",
       "      <th>Baileyfort</th>\n",
       "      <th>831 Norma Cove</th>\n",
       "      <td>B</td>\n",
       "      <td>D+</td>\n",
       "      <td>A+</td>\n",
       "      <td>D+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                   Culture         Services        \n",
       "Subcategory                            Restaurants Museums   Police Schools\n",
       "State City        Street                                                   \n",
       "AR    Allisonland 124 Diaz Brooks               C-      A+        F      C+\n",
       "IA    Amyburgh    163 Heather Neck               F       D       A+      A-\n",
       "GA    Amyburgh    941 Brian Expressway           B       B       D-      C+\n",
       "ID    Andrewshire 952 Ellis Drive               C+      A-       C+       A\n",
       "VT    Baileyfort  831 Norma Cove                 B      D+       A+      D+"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "neighborhoods.sort_index(level = [1, 2]).head()\n",
    "neighborhoods.sort_index(level = [\"City\", \"Street\"]).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AR</th>\n",
       "      <th>Allisonland</th>\n",
       "      <th>124 Diaz Brooks</th>\n",
       "      <td>C-</td>\n",
       "      <td>A+</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GA</th>\n",
       "      <th>Amyburgh</th>\n",
       "      <th>941 Brian Expressway</th>\n",
       "      <td>B</td>\n",
       "      <td>B</td>\n",
       "      <td>D-</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>IA</th>\n",
       "      <th>Amyburgh</th>\n",
       "      <th>163 Heather Neck</th>\n",
       "      <td>F</td>\n",
       "      <td>D</td>\n",
       "      <td>A+</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th>Andrewshire</th>\n",
       "      <th>952 Ellis Drive</th>\n",
       "      <td>C+</td>\n",
       "      <td>A-</td>\n",
       "      <td>C+</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UT</th>\n",
       "      <th>Baileyfort</th>\n",
       "      <th>919 Stewart Hills</th>\n",
       "      <td>D+</td>\n",
       "      <td>C+</td>\n",
       "      <td>A</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                   Culture         Services        \n",
       "Subcategory                            Restaurants Museums   Police Schools\n",
       "State City        Street                                                   \n",
       "AR    Allisonland 124 Diaz Brooks               C-      A+        F      C+\n",
       "GA    Amyburgh    941 Brian Expressway           B       B       D-      C+\n",
       "IA    Amyburgh    163 Heather Neck               F       D       A+      A-\n",
       "ID    Andrewshire 952 Ellis Drive               C+      A-       C+       A\n",
       "UT    Baileyfort  919 Stewart Hills             D+      C+        A       C"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.sort_index(\n",
    "    level = [\"City\", \"Street\"], ascending = [True, False]\n",
    ").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>MO</th>\n",
       "      <th>Fisherborough</th>\n",
       "      <th>244 Tracy View</th>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>D-</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SD</th>\n",
       "      <th>Port Curtisville</th>\n",
       "      <th>446 Cynthia Inlet</th>\n",
       "      <td>B</td>\n",
       "      <td>C-</td>\n",
       "      <td>B</td>\n",
       "      <td>D+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WV</th>\n",
       "      <th>Jimenezview</th>\n",
       "      <th>432 John Common</th>\n",
       "      <td>A+</td>\n",
       "      <td>A</td>\n",
       "      <td>F</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                 Culture             Services        \n",
       "Subcategory                              Museums Restaurants   Police Schools\n",
       "State City             Street                                                \n",
       "MO    Fisherborough    244 Tracy View          F          C+       D-      A+\n",
       "SD    Port Curtisville 446 Cynthia Inlet       B          C-        B      D+\n",
       "WV    Jimenezview      432 John Common        A+           A        F       B"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "neighborhoods.sort_index(axis = 1).head(3)\n",
    "neighborhoods.sort_index(axis = \"columns\").head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th>Services</th>\n",
       "      <th>Culture</th>\n",
       "      <th>Services</th>\n",
       "      <th>Culture</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Schools</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Police</th>\n",
       "      <th>Museums</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>MO</th>\n",
       "      <th>Fisherborough</th>\n",
       "      <th>244 Tracy View</th>\n",
       "      <td>A+</td>\n",
       "      <td>C+</td>\n",
       "      <td>D-</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SD</th>\n",
       "      <th>Port Curtisville</th>\n",
       "      <th>446 Cynthia Inlet</th>\n",
       "      <td>D+</td>\n",
       "      <td>C-</td>\n",
       "      <td>B</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WV</th>\n",
       "      <th>Jimenezview</th>\n",
       "      <th>432 John Common</th>\n",
       "      <td>B</td>\n",
       "      <td>A</td>\n",
       "      <td>F</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                 Services     Culture Services Culture\n",
       "Subcategory                               Schools Restaurants   Police Museums\n",
       "State City             Street                                                 \n",
       "MO    Fisherborough    244 Tracy View          A+          C+       D-       F\n",
       "SD    Port Curtisville 446 Cynthia Inlet       D+          C-        B       B\n",
       "WV    Jimenezview      432 John Common          B           A        F      A+"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.sort_index(\n",
    "    axis = 1, level = \"Subcategory\", ascending = False\n",
    ").head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "neighborhoods = neighborhoods.sort_index(ascending = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">AK</th>\n",
       "      <th>Rowlandchester</th>\n",
       "      <th>386 Rebecca Cove</th>\n",
       "      <td>C-</td>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Scottstad</th>\n",
       "      <th>082 Leblanc Freeway</th>\n",
       "      <td>D</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114 Jones Garden</th>\n",
       "      <td>D-</td>\n",
       "      <td>D-</td>\n",
       "      <td>D</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                     Culture         Services        \n",
       "Subcategory                              Restaurants Museums   Police Schools\n",
       "State City           Street                                                  \n",
       "AK    Rowlandchester 386 Rebecca Cove             C-      A-       A+       C\n",
       "      Scottstad      082 Leblanc Freeway           D      C-        D      B+\n",
       "                     114 Jones Garden             D-      D-        D       D"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.4 Selecting with a MultiIndex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>X</th>\n",
       "      <th>Y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   X  Y\n",
       "A  1  2\n",
       "B  3  4"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = [\n",
    "    [1, 2], \n",
    "    [3, 4]\n",
    "]\n",
    "\n",
    "df = pd.DataFrame(\n",
    "    data = data,\n",
    "    index = [\"A\", \"B\"],\n",
    "    columns = [\"X\", \"Y\"]\n",
    ")\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    1\n",
       "B    3\n",
       "Name: X, dtype: int64"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"X\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 7.4.1 Extracting One or More Columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">AK</th>\n",
       "      <th>Rowlandchester</th>\n",
       "      <th>386 Rebecca Cove</th>\n",
       "      <td>A+</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Scottstad</th>\n",
       "      <th>082 Leblanc Freeway</th>\n",
       "      <td>D</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114 Jones Garden</th>\n",
       "      <td>D</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stevenshire</th>\n",
       "      <th>238 Andrew Rue</th>\n",
       "      <td>A-</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AL</th>\n",
       "      <th>Clarkland</th>\n",
       "      <th>430 Douglas Mission</th>\n",
       "      <td>C+</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">WY</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Lake Nicole</th>\n",
       "      <th>754 Weaver Turnpike</th>\n",
       "      <td>B</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>933 Jennifer Burg</th>\n",
       "      <td>A-</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Martintown</th>\n",
       "      <th>013 Bell Mills</th>\n",
       "      <td>A-</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Port Jason</th>\n",
       "      <th>624 Faulkner Orchard</th>\n",
       "      <td>C+</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Reneeshire</th>\n",
       "      <th>717 Patel Square</th>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>251 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "Subcategory                               Police Schools\n",
       "State City           Street                             \n",
       "AK    Rowlandchester 386 Rebecca Cove         A+       C\n",
       "      Scottstad      082 Leblanc Freeway       D      B+\n",
       "                     114 Jones Garden          D       D\n",
       "      Stevenshire    238 Andrew Rue           A-      A-\n",
       "AL    Clarkland      430 Douglas Mission      C+      B+\n",
       "...                                          ...     ...\n",
       "WY    Lake Nicole    754 Weaver Turnpike       B       D\n",
       "                     933 Jennifer Burg        A-       C\n",
       "      Martintown     013 Bell Mills           A-      B-\n",
       "      Port Jason     624 Faulkner Orchard     C+      C+\n",
       "      Reneeshire     717 Patel Square          D       A\n",
       "\n",
       "[251 rows x 2 columns]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods[\"Services\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**NOTE**: I've commented out the code below so that the Notebook can run without raising an error."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "# neighborhoods[\"Schools\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "State  City            Street              \n",
       "AK     Rowlandchester  386 Rebecca Cove         C\n",
       "       Scottstad       082 Leblanc Freeway     B+\n",
       "                       114 Jones Garden         D\n",
       "       Stevenshire     238 Andrew Rue          A-\n",
       "AL     Clarkland       430 Douglas Mission     B+\n",
       "                                               ..\n",
       "WY     Lake Nicole     754 Weaver Turnpike      D\n",
       "                       933 Jennifer Burg        C\n",
       "       Martintown      013 Bell Mills          B-\n",
       "       Port Jason      624 Faulkner Orchard    C+\n",
       "       Reneeshire      717 Patel Square         A\n",
       "Name: (Services, Schools), Length: 251, dtype: object"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods[(\"Services\", \"Schools\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th>Services</th>\n",
       "      <th>Culture</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Schools</th>\n",
       "      <th>Museums</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">AK</th>\n",
       "      <th>Rowlandchester</th>\n",
       "      <th>386 Rebecca Cove</th>\n",
       "      <td>C</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Scottstad</th>\n",
       "      <th>082 Leblanc Freeway</th>\n",
       "      <td>B+</td>\n",
       "      <td>C-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114 Jones Garden</th>\n",
       "      <td>D</td>\n",
       "      <td>D-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stevenshire</th>\n",
       "      <th>238 Andrew Rue</th>\n",
       "      <td>A-</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AL</th>\n",
       "      <th>Clarkland</th>\n",
       "      <th>430 Douglas Mission</th>\n",
       "      <td>B+</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">WY</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Lake Nicole</th>\n",
       "      <th>754 Weaver Turnpike</th>\n",
       "      <td>D</td>\n",
       "      <td>D-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>933 Jennifer Burg</th>\n",
       "      <td>C</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Martintown</th>\n",
       "      <th>013 Bell Mills</th>\n",
       "      <td>B-</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Port Jason</th>\n",
       "      <th>624 Faulkner Orchard</th>\n",
       "      <td>C+</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Reneeshire</th>\n",
       "      <th>717 Patel Square</th>\n",
       "      <td>A</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>251 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                  Services Culture\n",
       "Subcategory                                Schools Museums\n",
       "State City           Street                               \n",
       "AK    Rowlandchester 386 Rebecca Cove            C      A-\n",
       "      Scottstad      082 Leblanc Freeway        B+      C-\n",
       "                     114 Jones Garden            D      D-\n",
       "      Stevenshire    238 Andrew Rue             A-       A\n",
       "AL    Clarkland      430 Douglas Mission        B+       F\n",
       "...                                            ...     ...\n",
       "WY    Lake Nicole    754 Weaver Turnpike         D      D-\n",
       "                     933 Jennifer Burg           C      A+\n",
       "      Martintown     013 Bell Mills             B-       D\n",
       "      Port Jason     624 Faulkner Orchard       C+       F\n",
       "      Reneeshire     717 Patel Square            A      B+\n",
       "\n",
       "[251 rows x 2 columns]"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods[[(\"Services\", \"Schools\"), (\"Culture\", \"Museums\")]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th>Services</th>\n",
       "      <th>Culture</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Schools</th>\n",
       "      <th>Museums</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">AK</th>\n",
       "      <th>Rowlandchester</th>\n",
       "      <th>386 Rebecca Cove</th>\n",
       "      <td>C</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Scottstad</th>\n",
       "      <th>082 Leblanc Freeway</th>\n",
       "      <td>B+</td>\n",
       "      <td>C-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114 Jones Garden</th>\n",
       "      <td>D</td>\n",
       "      <td>D-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stevenshire</th>\n",
       "      <th>238 Andrew Rue</th>\n",
       "      <td>A-</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AL</th>\n",
       "      <th>Clarkland</th>\n",
       "      <th>430 Douglas Mission</th>\n",
       "      <td>B+</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">WY</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">Lake Nicole</th>\n",
       "      <th>754 Weaver Turnpike</th>\n",
       "      <td>D</td>\n",
       "      <td>D-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>933 Jennifer Burg</th>\n",
       "      <td>C</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Martintown</th>\n",
       "      <th>013 Bell Mills</th>\n",
       "      <td>B-</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Port Jason</th>\n",
       "      <th>624 Faulkner Orchard</th>\n",
       "      <td>C+</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Reneeshire</th>\n",
       "      <th>717 Patel Square</th>\n",
       "      <td>A</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>251 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                  Services Culture\n",
       "Subcategory                                Schools Museums\n",
       "State City           Street                               \n",
       "AK    Rowlandchester 386 Rebecca Cove            C      A-\n",
       "      Scottstad      082 Leblanc Freeway        B+      C-\n",
       "                     114 Jones Garden            D      D-\n",
       "      Stevenshire    238 Andrew Rue             A-       A\n",
       "AL    Clarkland      430 Douglas Mission        B+       F\n",
       "...                                            ...     ...\n",
       "WY    Lake Nicole    754 Weaver Turnpike         D      D-\n",
       "                     933 Jennifer Burg           C      A+\n",
       "      Martintown     013 Bell Mills             B-       D\n",
       "      Port Jason     624 Faulkner Orchard       C+       F\n",
       "      Reneeshire     717 Patel Square            A      B+\n",
       "\n",
       "[251 rows x 2 columns]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "columns = [\n",
    "    (\"Services\", \"Schools\"),\n",
    "    (\"Culture\", \"Museums\")\n",
    "]\n",
    "\n",
    "neighborhoods[columns]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 7.4.2 Extracting One or More Rows with loc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>X</th>\n",
       "      <th>Y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   X  Y\n",
       "A  1  2\n",
       "B  3  4"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "X    1\n",
       "Y    2\n",
       "Name: A, dtype: int64"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\"A\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "X    3\n",
       "Y    4\n",
       "Name: B, dtype: int64"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Category  Subcategory\n",
       "Culture   Restaurants     C\n",
       "          Museums        D+\n",
       "Services  Police          B\n",
       "          Schools         B\n",
       "Name: (TX, Kingchester, 534 Gordon Falls), dtype: object"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.loc[(\"TX\", \"Kingchester\", \"534 Gordon Falls\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Dustinmouth</th>\n",
       "      <th>793 Cynthia Square</th>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>C-</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>North Jennifer</th>\n",
       "      <th>303 Alisha Road</th>\n",
       "      <td>D-</td>\n",
       "      <td>C+</td>\n",
       "      <td>C+</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ryanfort</th>\n",
       "      <th>934 David Run</th>\n",
       "      <td>F</td>\n",
       "      <td>B+</td>\n",
       "      <td>F</td>\n",
       "      <td>D-</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                              Culture         Services        \n",
       "Subcategory                       Restaurants Museums   Police Schools\n",
       "City           Street                                                 \n",
       "Dustinmouth    793 Cynthia Square          A-      A+       C-       A\n",
       "North Jennifer 303 Alisha Road             D-      C+       C+      A+\n",
       "Ryanfort       934 David Run                F      B+        F      D-"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.loc[\"CA\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>793 Cynthia Square</th>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>C-</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category               Culture         Services        \n",
       "Subcategory        Restaurants Museums   Police Schools\n",
       "Street                                                 \n",
       "793 Cynthia Square          A-      A+       C-       A"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.loc[\"CA\", \"Dustinmouth\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Dustinmouth</th>\n",
       "      <th>793 Cynthia Square</th>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>North Jennifer</th>\n",
       "      <th>303 Alisha Road</th>\n",
       "      <td>D-</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ryanfort</th>\n",
       "      <th>934 David Run</th>\n",
       "      <td>F</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Subcategory                       Restaurants Museums\n",
       "City           Street                                \n",
       "Dustinmouth    793 Cynthia Square          A-      A+\n",
       "North Jennifer 303 Alisha Road             D-      C+\n",
       "Ryanfort       934 David Run                F      B+"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.loc[\"CA\", \"Culture\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>793 Cynthia Square</th>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>C-</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category               Culture         Services        \n",
       "Subcategory        Restaurants Museums   Police Schools\n",
       "Street                                                 \n",
       "793 Cynthia Square          A-      A+       C-       A"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.loc[(\"CA\", \"Dustinmouth\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>Subcategory</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>793 Cynthia Square</th>\n",
       "      <td>C-</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Subcategory        Police Schools\n",
       "Street                           \n",
       "793 Cynthia Square     C-       A"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.loc[(\"CA\", \"Dustinmouth\"), (\"Services\",)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Street\n",
       "793 Cynthia Square    A\n",
       "Name: (Services, Schools), dtype: object"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.loc[(\"CA\", \"Dustinmouth\"), (\"Services\", \"Schools\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">NE</th>\n",
       "      <th>Barryborough</th>\n",
       "      <th>460 Anna Tunnel</th>\n",
       "      <td>A+</td>\n",
       "      <td>A+</td>\n",
       "      <td>B</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Shawnchester</th>\n",
       "      <th>802 Cook Cliff</th>\n",
       "      <td>D-</td>\n",
       "      <td>D+</td>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Kennethmouth</th>\n",
       "      <th>346 Wallace Pass</th>\n",
       "      <td>C-</td>\n",
       "      <td>B-</td>\n",
       "      <td>A</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Nathan</th>\n",
       "      <th>821 Jake Fork</th>\n",
       "      <td>C+</td>\n",
       "      <td>D</td>\n",
       "      <td>D+</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">NH</th>\n",
       "      <th>Courtneyfort</th>\n",
       "      <th>697 Spencer Isle</th>\n",
       "      <td>A+</td>\n",
       "      <td>A+</td>\n",
       "      <td>C+</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>East Deborahberg</th>\n",
       "      <th>271 Ryan Mount</th>\n",
       "      <td>B</td>\n",
       "      <td>C</td>\n",
       "      <td>D+</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ingramton</th>\n",
       "      <th>430 Calvin Underpass</th>\n",
       "      <td>C+</td>\n",
       "      <td>D+</td>\n",
       "      <td>C</td>\n",
       "      <td>C-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>North Latoya</th>\n",
       "      <th>603 Clark Mount</th>\n",
       "      <td>D-</td>\n",
       "      <td>A-</td>\n",
       "      <td>B+</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Tara</th>\n",
       "      <th>559 Michael Glens</th>\n",
       "      <td>C-</td>\n",
       "      <td>C-</td>\n",
       "      <td>F</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                          Culture         Services  \\\n",
       "Subcategory                                   Restaurants Museums   Police   \n",
       "State City               Street                                              \n",
       "NE    Barryborough       460 Anna Tunnel               A+      A+        B   \n",
       "      Shawnchester       802 Cook Cliff                D-      D+        D   \n",
       "      South Kennethmouth 346 Wallace Pass              C-      B-        A   \n",
       "      South Nathan       821 Jake Fork                 C+       D       D+   \n",
       "NH    Courtneyfort       697 Spencer Isle              A+      A+       C+   \n",
       "      East Deborahberg   271 Ryan Mount                 B       C       D+   \n",
       "      Ingramton          430 Calvin Underpass          C+      D+        C   \n",
       "      North Latoya       603 Clark Mount               D-      A-       B+   \n",
       "      South Tara         559 Michael Glens             C-      C-        F   \n",
       "\n",
       "Category                                               \n",
       "Subcategory                                   Schools  \n",
       "State City               Street                        \n",
       "NE    Barryborough       460 Anna Tunnel            A  \n",
       "      Shawnchester       802 Cook Cliff             A  \n",
       "      South Kennethmouth 346 Wallace Pass          A-  \n",
       "      South Nathan       821 Jake Fork              A  \n",
       "NH    Courtneyfort       697 Spencer Isle          A+  \n",
       "      East Deborahberg   271 Ryan Mount            B-  \n",
       "      Ingramton          430 Calvin Underpass      C-  \n",
       "      North Latoya       603 Clark Mount           B-  \n",
       "      South Tara         559 Michael Glens          B  "
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods[\"NE\":\"NH\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">NE</th>\n",
       "      <th>Shawnchester</th>\n",
       "      <th>802 Cook Cliff</th>\n",
       "      <td>D-</td>\n",
       "      <td>D+</td>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Kennethmouth</th>\n",
       "      <th>346 Wallace Pass</th>\n",
       "      <td>C-</td>\n",
       "      <td>B-</td>\n",
       "      <td>A</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Nathan</th>\n",
       "      <th>821 Jake Fork</th>\n",
       "      <td>C+</td>\n",
       "      <td>D</td>\n",
       "      <td>D+</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">NH</th>\n",
       "      <th>Courtneyfort</th>\n",
       "      <th>697 Spencer Isle</th>\n",
       "      <td>A+</td>\n",
       "      <td>A+</td>\n",
       "      <td>C+</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>East Deborahberg</th>\n",
       "      <th>271 Ryan Mount</th>\n",
       "      <td>B</td>\n",
       "      <td>C</td>\n",
       "      <td>D+</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ingramton</th>\n",
       "      <th>430 Calvin Underpass</th>\n",
       "      <td>C+</td>\n",
       "      <td>D+</td>\n",
       "      <td>C</td>\n",
       "      <td>C-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>North Latoya</th>\n",
       "      <th>603 Clark Mount</th>\n",
       "      <td>D-</td>\n",
       "      <td>A-</td>\n",
       "      <td>B+</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                          Culture         Services  \\\n",
       "Subcategory                                   Restaurants Museums   Police   \n",
       "State City               Street                                              \n",
       "NE    Shawnchester       802 Cook Cliff                D-      D+        D   \n",
       "      South Kennethmouth 346 Wallace Pass              C-      B-        A   \n",
       "      South Nathan       821 Jake Fork                 C+       D       D+   \n",
       "NH    Courtneyfort       697 Spencer Isle              A+      A+       C+   \n",
       "      East Deborahberg   271 Ryan Mount                 B       C       D+   \n",
       "      Ingramton          430 Calvin Underpass          C+      D+        C   \n",
       "      North Latoya       603 Clark Mount               D-      A-       B+   \n",
       "\n",
       "Category                                               \n",
       "Subcategory                                   Schools  \n",
       "State City               Street                        \n",
       "NE    Shawnchester       802 Cook Cliff             A  \n",
       "      South Kennethmouth 346 Wallace Pass          A-  \n",
       "      South Nathan       821 Jake Fork              A  \n",
       "NH    Courtneyfort       697 Spencer Isle          A+  \n",
       "      East Deborahberg   271 Ryan Mount            B-  \n",
       "      Ingramton          430 Calvin Underpass      C-  \n",
       "      North Latoya       603 Clark Mount           B-  "
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.loc[(\"NE\", \"Shawnchester\"):(\"NH\", \"North Latoya\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">NE</th>\n",
       "      <th>Shawnchester</th>\n",
       "      <th>802 Cook Cliff</th>\n",
       "      <td>D-</td>\n",
       "      <td>D+</td>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Kennethmouth</th>\n",
       "      <th>346 Wallace Pass</th>\n",
       "      <td>C-</td>\n",
       "      <td>B-</td>\n",
       "      <td>A</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Nathan</th>\n",
       "      <th>821 Jake Fork</th>\n",
       "      <td>C+</td>\n",
       "      <td>D</td>\n",
       "      <td>D+</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">NH</th>\n",
       "      <th>Courtneyfort</th>\n",
       "      <th>697 Spencer Isle</th>\n",
       "      <td>A+</td>\n",
       "      <td>A+</td>\n",
       "      <td>C+</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>East Deborahberg</th>\n",
       "      <th>271 Ryan Mount</th>\n",
       "      <td>B</td>\n",
       "      <td>C</td>\n",
       "      <td>D+</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ingramton</th>\n",
       "      <th>430 Calvin Underpass</th>\n",
       "      <td>C+</td>\n",
       "      <td>D+</td>\n",
       "      <td>C</td>\n",
       "      <td>C-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>North Latoya</th>\n",
       "      <th>603 Clark Mount</th>\n",
       "      <td>D-</td>\n",
       "      <td>A-</td>\n",
       "      <td>B+</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                          Culture         Services  \\\n",
       "Subcategory                                   Restaurants Museums   Police   \n",
       "State City               Street                                              \n",
       "NE    Shawnchester       802 Cook Cliff                D-      D+        D   \n",
       "      South Kennethmouth 346 Wallace Pass              C-      B-        A   \n",
       "      South Nathan       821 Jake Fork                 C+       D       D+   \n",
       "NH    Courtneyfort       697 Spencer Isle              A+      A+       C+   \n",
       "      East Deborahberg   271 Ryan Mount                 B       C       D+   \n",
       "      Ingramton          430 Calvin Underpass          C+      D+        C   \n",
       "      North Latoya       603 Clark Mount               D-      A-       B+   \n",
       "\n",
       "Category                                               \n",
       "Subcategory                                   Schools  \n",
       "State City               Street                        \n",
       "NE    Shawnchester       802 Cook Cliff             A  \n",
       "      South Kennethmouth 346 Wallace Pass          A-  \n",
       "      South Nathan       821 Jake Fork              A  \n",
       "NH    Courtneyfort       697 Spencer Isle          A+  \n",
       "      East Deborahberg   271 Ryan Mount            B-  \n",
       "      Ingramton          430 Calvin Underpass      C-  \n",
       "      North Latoya       603 Clark Mount           B-  "
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "start = (\"NE\", \"Shawnchester\")\n",
    "end   = (\"NH\", \"North Latoya\")\n",
    "neighborhoods.loc[start:end]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">NE</th>\n",
       "      <th>Shawnchester</th>\n",
       "      <th>802 Cook Cliff</th>\n",
       "      <td>D-</td>\n",
       "      <td>D+</td>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Kennethmouth</th>\n",
       "      <th>346 Wallace Pass</th>\n",
       "      <td>C-</td>\n",
       "      <td>B-</td>\n",
       "      <td>A</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Nathan</th>\n",
       "      <th>821 Jake Fork</th>\n",
       "      <td>C+</td>\n",
       "      <td>D</td>\n",
       "      <td>D+</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">NH</th>\n",
       "      <th>Courtneyfort</th>\n",
       "      <th>697 Spencer Isle</th>\n",
       "      <td>A+</td>\n",
       "      <td>A+</td>\n",
       "      <td>C+</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>East Deborahberg</th>\n",
       "      <th>271 Ryan Mount</th>\n",
       "      <td>B</td>\n",
       "      <td>C</td>\n",
       "      <td>D+</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ingramton</th>\n",
       "      <th>430 Calvin Underpass</th>\n",
       "      <td>C+</td>\n",
       "      <td>D+</td>\n",
       "      <td>C</td>\n",
       "      <td>C-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>North Latoya</th>\n",
       "      <th>603 Clark Mount</th>\n",
       "      <td>D-</td>\n",
       "      <td>A-</td>\n",
       "      <td>B+</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South Tara</th>\n",
       "      <th>559 Michael Glens</th>\n",
       "      <td>C-</td>\n",
       "      <td>C-</td>\n",
       "      <td>F</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                          Culture         Services  \\\n",
       "Subcategory                                   Restaurants Museums   Police   \n",
       "State City               Street                                              \n",
       "NE    Shawnchester       802 Cook Cliff                D-      D+        D   \n",
       "      South Kennethmouth 346 Wallace Pass              C-      B-        A   \n",
       "      South Nathan       821 Jake Fork                 C+       D       D+   \n",
       "NH    Courtneyfort       697 Spencer Isle              A+      A+       C+   \n",
       "      East Deborahberg   271 Ryan Mount                 B       C       D+   \n",
       "      Ingramton          430 Calvin Underpass          C+      D+        C   \n",
       "      North Latoya       603 Clark Mount               D-      A-       B+   \n",
       "      South Tara         559 Michael Glens             C-      C-        F   \n",
       "\n",
       "Category                                               \n",
       "Subcategory                                   Schools  \n",
       "State City               Street                        \n",
       "NE    Shawnchester       802 Cook Cliff             A  \n",
       "      South Kennethmouth 346 Wallace Pass          A-  \n",
       "      South Nathan       821 Jake Fork              A  \n",
       "NH    Courtneyfort       697 Spencer Isle          A+  \n",
       "      East Deborahberg   271 Ryan Mount            B-  \n",
       "      Ingramton          430 Calvin Underpass      C-  \n",
       "      North Latoya       603 Clark Mount           B-  \n",
       "      South Tara         559 Michael Glens          B  "
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.loc[(\"NE\", \"Shawnchester\"):(\"NH\")]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 7.4.3 Extracting One or More Rows with iloc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Category  Subcategory\n",
       "Culture   Restaurants    A+\n",
       "          Museums         A\n",
       "Services  Police         A+\n",
       "          Schools        C+\n",
       "Name: (CT, East Jessicaland, 208 Todd Knolls), dtype: object"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.iloc[25]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'A+'"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.iloc[25, 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>CT</th>\n",
       "      <th>East Jessicaland</th>\n",
       "      <th>208 Todd Knolls</th>\n",
       "      <td>A+</td>\n",
       "      <td>A</td>\n",
       "      <td>A+</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DC</th>\n",
       "      <th>East Lisaview</th>\n",
       "      <th>910 Sandy Ramp</th>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>B</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                   Culture         Services        \n",
       "Subcategory                            Restaurants Museums   Police Schools\n",
       "State City             Street                                              \n",
       "CT    East Jessicaland 208 Todd Knolls          A+       A       A+      C+\n",
       "DC    East Lisaview    910 Sandy Ramp           A-      A+        B       B"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.iloc[[25, 30]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">CT</th>\n",
       "      <th>East Jessicaland</th>\n",
       "      <th>208 Todd Knolls</th>\n",
       "      <td>A+</td>\n",
       "      <td>A</td>\n",
       "      <td>A+</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New Adrianhaven</th>\n",
       "      <th>048 Brian Cove</th>\n",
       "      <td>A-</td>\n",
       "      <td>C+</td>\n",
       "      <td>A+</td>\n",
       "      <td>D-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Port Mike</th>\n",
       "      <th>410 Keith Lodge</th>\n",
       "      <td>D-</td>\n",
       "      <td>A</td>\n",
       "      <td>B+</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sethstad</th>\n",
       "      <th>139 Bailey Grove</th>\n",
       "      <td>C</td>\n",
       "      <td>C-</td>\n",
       "      <td>C+</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DC</th>\n",
       "      <th>East Jessica</th>\n",
       "      <th>149 Norman Crossing</th>\n",
       "      <td>A-</td>\n",
       "      <td>C-</td>\n",
       "      <td>C+</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                       Culture         Services  \\\n",
       "Subcategory                                Restaurants Museums   Police   \n",
       "State City             Street                                             \n",
       "CT    East Jessicaland 208 Todd Knolls              A+       A       A+   \n",
       "      New Adrianhaven  048 Brian Cove               A-      C+       A+   \n",
       "      Port Mike        410 Keith Lodge              D-       A       B+   \n",
       "      Sethstad         139 Bailey Grove              C      C-       C+   \n",
       "DC    East Jessica     149 Norman Crossing          A-      C-       C+   \n",
       "\n",
       "Category                                            \n",
       "Subcategory                                Schools  \n",
       "State City             Street                       \n",
       "CT    East Jessicaland 208 Todd Knolls          C+  \n",
       "      New Adrianhaven  048 Brian Cove           D-  \n",
       "      Port Mike        410 Keith Lodge           D  \n",
       "      Sethstad         139 Bailey Grove         A+  \n",
       "DC    East Jessica     149 Norman Crossing      A-  "
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.iloc[25:30]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th>Culture</th>\n",
       "      <th>Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">CT</th>\n",
       "      <th>East Jessicaland</th>\n",
       "      <th>208 Todd Knolls</th>\n",
       "      <td>A</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New Adrianhaven</th>\n",
       "      <th>048 Brian Cove</th>\n",
       "      <td>C+</td>\n",
       "      <td>A+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Port Mike</th>\n",
       "      <th>410 Keith Lodge</th>\n",
       "      <td>A</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sethstad</th>\n",
       "      <th>139 Bailey Grove</th>\n",
       "      <td>C-</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DC</th>\n",
       "      <th>East Jessica</th>\n",
       "      <th>149 Norman Crossing</th>\n",
       "      <td>C-</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                   Culture Services\n",
       "Subcategory                                Museums   Police\n",
       "State City             Street                              \n",
       "CT    East Jessicaland 208 Todd Knolls           A       A+\n",
       "      New Adrianhaven  048 Brian Cove           C+       A+\n",
       "      Port Mike        410 Keith Lodge           A       B+\n",
       "      Sethstad         139 Bailey Grove         C-       C+\n",
       "DC    East Jessica     149 Norman Crossing      C-       C+"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.iloc[25:30, 1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">WY</th>\n",
       "      <th>Lake Nicole</th>\n",
       "      <th>933 Jennifer Burg</th>\n",
       "      <td>A-</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Martintown</th>\n",
       "      <th>013 Bell Mills</th>\n",
       "      <td>A-</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Port Jason</th>\n",
       "      <th>624 Faulkner Orchard</th>\n",
       "      <td>C+</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Reneeshire</th>\n",
       "      <th>717 Patel Square</th>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                               Services        \n",
       "Subcategory                              Police Schools\n",
       "State City        Street                               \n",
       "WY    Lake Nicole 933 Jennifer Burg          A-       C\n",
       "      Martintown  013 Bell Mills             A-      B-\n",
       "      Port Jason  624 Faulkner Orchard       C+      C+\n",
       "      Reneeshire  717 Patel Square            D       A"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.iloc[-4:, -2:]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.5 Cross Sections"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>OR</th>\n",
       "      <th>650 Angela Track</th>\n",
       "      <td>D</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">WY</th>\n",
       "      <th>754 Weaver Turnpike</th>\n",
       "      <td>B</td>\n",
       "      <td>D-</td>\n",
       "      <td>B</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>933 Jennifer Burg</th>\n",
       "      <td>C</td>\n",
       "      <td>A+</td>\n",
       "      <td>A-</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                      Culture         Services        \n",
       "Subcategory               Restaurants Museums   Police Schools\n",
       "State Street                                                  \n",
       "OR    650 Angela Track              D      C-        D       F\n",
       "WY    754 Weaver Turnpike           B      D-        B       D\n",
       "      933 Jennifer Burg             C      A+       A-       C"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "neighborhoods.xs(key = \"Lake Nicole\", level = 1)\n",
    "neighborhoods.xs(key = \"Lake Nicole\", level = \"City\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th>Culture</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">AK</th>\n",
       "      <th>Rowlandchester</th>\n",
       "      <th>386 Rebecca Cove</th>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Scottstad</th>\n",
       "      <th>082 Leblanc Freeway</th>\n",
       "      <td>C-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114 Jones Garden</th>\n",
       "      <td>D-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stevenshire</th>\n",
       "      <th>238 Andrew Rue</th>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AL</th>\n",
       "      <th>Clarkland</th>\n",
       "      <th>430 Douglas Mission</th>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                 Culture\n",
       "State City           Street                     \n",
       "AK    Rowlandchester 386 Rebecca Cove         A-\n",
       "      Scottstad      082 Leblanc Freeway      C-\n",
       "                     114 Jones Garden         D-\n",
       "      Stevenshire    238 Andrew Rue            A\n",
       "AL    Clarkland      430 Douglas Mission       F"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.xs(\n",
    "    axis = \"columns\", key = \"Museums\", level = \"Subcategory\"\n",
    ").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>City</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Stevenshire</th>\n",
       "      <td>D-</td>\n",
       "      <td>A</td>\n",
       "      <td>A-</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category        Culture         Services        \n",
       "Subcategory Restaurants Museums   Police Schools\n",
       "City                                            \n",
       "Stevenshire          D-       A       A-      A-"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "neighborhoods.xs(\n",
    "    key = (\"AK\", \"238 Andrew Rue\"), level = [\"State\", \"Street\"]\n",
    ")\n",
    "\n",
    "neighborhoods.xs(\n",
    "    key = (\"AK\", \"238 Andrew Rue\"), level = [0, 2]\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.6. Manipulating the Index"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 7.6.1 Resetting the Index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">AK</th>\n",
       "      <th>Rowlandchester</th>\n",
       "      <th>386 Rebecca Cove</th>\n",
       "      <td>C-</td>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Scottstad</th>\n",
       "      <th>082 Leblanc Freeway</th>\n",
       "      <td>D</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114 Jones Garden</th>\n",
       "      <td>D-</td>\n",
       "      <td>D-</td>\n",
       "      <td>D</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stevenshire</th>\n",
       "      <th>238 Andrew Rue</th>\n",
       "      <td>D-</td>\n",
       "      <td>A</td>\n",
       "      <td>A-</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AL</th>\n",
       "      <th>Clarkland</th>\n",
       "      <th>430 Douglas Mission</th>\n",
       "      <td>A</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                     Culture         Services        \n",
       "Subcategory                              Restaurants Museums   Police Schools\n",
       "State City           Street                                                  \n",
       "AK    Rowlandchester 386 Rebecca Cove             C-      A-       A+       C\n",
       "      Scottstad      082 Leblanc Freeway           D      C-        D      B+\n",
       "                     114 Jones Garden             D-      D-        D       D\n",
       "      Stevenshire    238 Andrew Rue               D-       A       A-      A-\n",
       "AL    Clarkland      430 Douglas Mission           A       F       C+      B+"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>City</th>\n",
       "      <th>State</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Rowlandchester</th>\n",
       "      <th>AK</th>\n",
       "      <th>386 Rebecca Cove</th>\n",
       "      <td>C-</td>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Scottstad</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">AK</th>\n",
       "      <th>082 Leblanc Freeway</th>\n",
       "      <td>D</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114 Jones Garden</th>\n",
       "      <td>D-</td>\n",
       "      <td>D-</td>\n",
       "      <td>D</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stevenshire</th>\n",
       "      <th>AK</th>\n",
       "      <th>238 Andrew Rue</th>\n",
       "      <td>D-</td>\n",
       "      <td>A</td>\n",
       "      <td>A-</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Clarkland</th>\n",
       "      <th>AL</th>\n",
       "      <th>430 Douglas Mission</th>\n",
       "      <td>A</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                     Culture         Services        \n",
       "Subcategory                              Restaurants Museums   Police Schools\n",
       "City           State Street                                                  \n",
       "Rowlandchester AK    386 Rebecca Cove             C-      A-       A+       C\n",
       "Scottstad      AK    082 Leblanc Freeway           D      C-        D      B+\n",
       "                     114 Jones Garden             D-      D-        D       D\n",
       "Stevenshire    AK    238 Andrew Rue               D-       A       A-      A-\n",
       "Clarkland      AL    430 Douglas Mission           A       F       C+      B+"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_order = [\"City\", \"State\", \"Street\"]\n",
    "neighborhoods.reorder_levels(order = new_order).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>City</th>\n",
       "      <th>State</th>\n",
       "      <th>Street</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Rowlandchester</th>\n",
       "      <th>AK</th>\n",
       "      <th>386 Rebecca Cove</th>\n",
       "      <td>C-</td>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Scottstad</th>\n",
       "      <th rowspan=\"2\" valign=\"top\">AK</th>\n",
       "      <th>082 Leblanc Freeway</th>\n",
       "      <td>D</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>114 Jones Garden</th>\n",
       "      <td>D-</td>\n",
       "      <td>D-</td>\n",
       "      <td>D</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stevenshire</th>\n",
       "      <th>AK</th>\n",
       "      <th>238 Andrew Rue</th>\n",
       "      <td>D-</td>\n",
       "      <td>A</td>\n",
       "      <td>A-</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Clarkland</th>\n",
       "      <th>AL</th>\n",
       "      <th>430 Douglas Mission</th>\n",
       "      <td>A</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                     Culture         Services        \n",
       "Subcategory                              Restaurants Museums   Police Schools\n",
       "City           State Street                                                  \n",
       "Rowlandchester AK    386 Rebecca Cove             C-      A-       A+       C\n",
       "Scottstad      AK    082 Leblanc Freeway           D      C-        D      B+\n",
       "                     114 Jones Garden             D-      D-        D       D\n",
       "Stevenshire    AK    238 Andrew Rue               D-       A       A-      A-\n",
       "Clarkland      AL    430 Douglas Mission           A       F       C+      B+"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.reorder_levels(order = [1, 0, 2]).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th>Category</th>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Subcategory</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>246</th>\n",
       "      <td>WY</td>\n",
       "      <td>Lake Nicole</td>\n",
       "      <td>754 Weaver Turnpike</td>\n",
       "      <td>B</td>\n",
       "      <td>D-</td>\n",
       "      <td>B</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>247</th>\n",
       "      <td>WY</td>\n",
       "      <td>Lake Nicole</td>\n",
       "      <td>933 Jennifer Burg</td>\n",
       "      <td>C</td>\n",
       "      <td>A+</td>\n",
       "      <td>A-</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>WY</td>\n",
       "      <td>Martintown</td>\n",
       "      <td>013 Bell Mills</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>A-</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>249</th>\n",
       "      <td>WY</td>\n",
       "      <td>Port Jason</td>\n",
       "      <td>624 Faulkner Orchard</td>\n",
       "      <td>A-</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>250</th>\n",
       "      <td>WY</td>\n",
       "      <td>Reneeshire</td>\n",
       "      <td>717 Patel Square</td>\n",
       "      <td>B</td>\n",
       "      <td>B+</td>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category    State         City                Street     Culture          \\\n",
       "Subcategory                                          Restaurants Museums   \n",
       "246            WY  Lake Nicole   754 Weaver Turnpike           B      D-   \n",
       "247            WY  Lake Nicole     933 Jennifer Burg           C      A+   \n",
       "248            WY   Martintown        013 Bell Mills          C-       D   \n",
       "249            WY   Port Jason  624 Faulkner Orchard          A-       F   \n",
       "250            WY   Reneeshire      717 Patel Square           B      B+   \n",
       "\n",
       "Category    Services          \n",
       "Subcategory   Police Schools  \n",
       "246                B       D  \n",
       "247               A-       C  \n",
       "248               A-      B-  \n",
       "249               C+      C+  \n",
       "250                D       A  "
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.reset_index().tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"3\" halign=\"left\"></th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Subcategory</th>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>246</th>\n",
       "      <td>WY</td>\n",
       "      <td>Lake Nicole</td>\n",
       "      <td>754 Weaver Turnpike</td>\n",
       "      <td>B</td>\n",
       "      <td>D-</td>\n",
       "      <td>B</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>247</th>\n",
       "      <td>WY</td>\n",
       "      <td>Lake Nicole</td>\n",
       "      <td>933 Jennifer Burg</td>\n",
       "      <td>C</td>\n",
       "      <td>A+</td>\n",
       "      <td>A-</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>WY</td>\n",
       "      <td>Martintown</td>\n",
       "      <td>013 Bell Mills</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>A-</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>249</th>\n",
       "      <td>WY</td>\n",
       "      <td>Port Jason</td>\n",
       "      <td>624 Faulkner Orchard</td>\n",
       "      <td>A-</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>250</th>\n",
       "      <td>WY</td>\n",
       "      <td>Reneeshire</td>\n",
       "      <td>717 Patel Square</td>\n",
       "      <td>B</td>\n",
       "      <td>B+</td>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                                                 Culture          \\\n",
       "Subcategory State         City                Street Restaurants Museums   \n",
       "246            WY  Lake Nicole   754 Weaver Turnpike           B      D-   \n",
       "247            WY  Lake Nicole     933 Jennifer Burg           C      A+   \n",
       "248            WY   Martintown        013 Bell Mills          C-       D   \n",
       "249            WY   Port Jason  624 Faulkner Orchard          A-       F   \n",
       "250            WY   Reneeshire      717 Patel Square           B      B+   \n",
       "\n",
       "Category    Services          \n",
       "Subcategory   Police Schools  \n",
       "246                B       D  \n",
       "247               A-       C  \n",
       "248               A-      B-  \n",
       "249               C+      C+  \n",
       "250                D       A  "
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "neighborhoods.reset_index(col_level = 1).tail()\n",
    "neighborhoods.reset_index(col_level = \"Subcategory\").tail() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"3\" halign=\"left\">Address</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Subcategory</th>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>246</th>\n",
       "      <td>WY</td>\n",
       "      <td>Lake Nicole</td>\n",
       "      <td>754 Weaver Turnpike</td>\n",
       "      <td>B</td>\n",
       "      <td>D-</td>\n",
       "      <td>B</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>247</th>\n",
       "      <td>WY</td>\n",
       "      <td>Lake Nicole</td>\n",
       "      <td>933 Jennifer Burg</td>\n",
       "      <td>C</td>\n",
       "      <td>A+</td>\n",
       "      <td>A-</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>WY</td>\n",
       "      <td>Martintown</td>\n",
       "      <td>013 Bell Mills</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>A-</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>249</th>\n",
       "      <td>WY</td>\n",
       "      <td>Port Jason</td>\n",
       "      <td>624 Faulkner Orchard</td>\n",
       "      <td>A-</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>250</th>\n",
       "      <td>WY</td>\n",
       "      <td>Reneeshire</td>\n",
       "      <td>717 Patel Square</td>\n",
       "      <td>B</td>\n",
       "      <td>B+</td>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category    Address                                        Culture          \\\n",
       "Subcategory   State         City                Street Restaurants Museums   \n",
       "246              WY  Lake Nicole   754 Weaver Turnpike           B      D-   \n",
       "247              WY  Lake Nicole     933 Jennifer Burg           C      A+   \n",
       "248              WY   Martintown        013 Bell Mills          C-       D   \n",
       "249              WY   Port Jason  624 Faulkner Orchard          A-       F   \n",
       "250              WY   Reneeshire      717 Patel Square           B      B+   \n",
       "\n",
       "Category    Services          \n",
       "Subcategory   Police Schools  \n",
       "246                B       D  \n",
       "247               A-       C  \n",
       "248               A-      B-  \n",
       "249               C+      C+  \n",
       "250                D       A  "
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.reset_index(\n",
    "    col_fill = \"Address\", col_level = \"Subcategory\"\n",
    ").tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th>Street</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th></th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">WY</th>\n",
       "      <th>Lake Nicole</th>\n",
       "      <td>754 Weaver Turnpike</td>\n",
       "      <td>B</td>\n",
       "      <td>D-</td>\n",
       "      <td>B</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lake Nicole</th>\n",
       "      <td>933 Jennifer Burg</td>\n",
       "      <td>C</td>\n",
       "      <td>A+</td>\n",
       "      <td>A-</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Martintown</th>\n",
       "      <td>013 Bell Mills</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>A-</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Port Jason</th>\n",
       "      <td>624 Faulkner Orchard</td>\n",
       "      <td>A-</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Reneeshire</th>\n",
       "      <td>717 Patel Square</td>\n",
       "      <td>B</td>\n",
       "      <td>B+</td>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                         Street     Culture         Services        \n",
       "Subcategory                             Restaurants Museums   Police Schools\n",
       "State City                                                                  \n",
       "WY    Lake Nicole   754 Weaver Turnpike           B      D-        B       D\n",
       "      Lake Nicole     933 Jennifer Burg           C      A+       A-       C\n",
       "      Martintown         013 Bell Mills          C-       D       A-      B-\n",
       "      Port Jason   624 Faulkner Orchard          A-       F       C+      C+\n",
       "      Reneeshire       717 Patel Square           B      B+        D       A"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.reset_index(level = \"Street\").tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th>Category</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Subcategory</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>WY</th>\n",
       "      <td>Lake Nicole</td>\n",
       "      <td>754 Weaver Turnpike</td>\n",
       "      <td>B</td>\n",
       "      <td>D-</td>\n",
       "      <td>B</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WY</th>\n",
       "      <td>Lake Nicole</td>\n",
       "      <td>933 Jennifer Burg</td>\n",
       "      <td>C</td>\n",
       "      <td>A+</td>\n",
       "      <td>A-</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WY</th>\n",
       "      <td>Martintown</td>\n",
       "      <td>013 Bell Mills</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>A-</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WY</th>\n",
       "      <td>Port Jason</td>\n",
       "      <td>624 Faulkner Orchard</td>\n",
       "      <td>A-</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WY</th>\n",
       "      <td>Reneeshire</td>\n",
       "      <td>717 Patel Square</td>\n",
       "      <td>B</td>\n",
       "      <td>B+</td>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category            City                Street     Culture         Services  \\\n",
       "Subcategory                                    Restaurants Museums   Police   \n",
       "State                                                                         \n",
       "WY           Lake Nicole   754 Weaver Turnpike           B      D-        B   \n",
       "WY           Lake Nicole     933 Jennifer Burg           C      A+       A-   \n",
       "WY            Martintown        013 Bell Mills          C-       D       A-   \n",
       "WY            Port Jason  624 Faulkner Orchard          A-       F       C+   \n",
       "WY            Reneeshire      717 Patel Square           B      B+        D   \n",
       "\n",
       "Category             \n",
       "Subcategory Schools  \n",
       "State                \n",
       "WY                D  \n",
       "WY                C  \n",
       "WY               B-  \n",
       "WY               C+  \n",
       "WY                A  "
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.reset_index(level = [\"Street\", \"City\"]).tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">WY</th>\n",
       "      <th>Lake Nicole</th>\n",
       "      <td>B</td>\n",
       "      <td>D-</td>\n",
       "      <td>B</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lake Nicole</th>\n",
       "      <td>C</td>\n",
       "      <td>A+</td>\n",
       "      <td>A-</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Martintown</th>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>A-</td>\n",
       "      <td>B-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Port Jason</th>\n",
       "      <td>A-</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>C+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Reneeshire</th>\n",
       "      <td>B</td>\n",
       "      <td>B+</td>\n",
       "      <td>D</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category              Culture         Services        \n",
       "Subcategory       Restaurants Museums   Police Schools\n",
       "State City                                            \n",
       "WY    Lake Nicole           B      D-        B       D\n",
       "      Lake Nicole           C      A+       A-       C\n",
       "      Martintown           C-       D       A-      B-\n",
       "      Port Jason           A-       F       C+      C+\n",
       "      Reneeshire            B      B+        D       A"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.reset_index(level = \"Street\", drop = True).tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "neighborhoods = neighborhoods.reset_index()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 7.6.2 Setting the Index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th>Category</th>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Subcategory</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AK</td>\n",
       "      <td>Rowlandchester</td>\n",
       "      <td>386 Rebecca Cove</td>\n",
       "      <td>C-</td>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>AK</td>\n",
       "      <td>Scottstad</td>\n",
       "      <td>082 Leblanc Freeway</td>\n",
       "      <td>D</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>AK</td>\n",
       "      <td>Scottstad</td>\n",
       "      <td>114 Jones Garden</td>\n",
       "      <td>D-</td>\n",
       "      <td>D-</td>\n",
       "      <td>D</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category    State            City               Street     Culture          \\\n",
       "Subcategory                                            Restaurants Museums   \n",
       "0              AK  Rowlandchester     386 Rebecca Cove          C-      A-   \n",
       "1              AK       Scottstad  082 Leblanc Freeway           D      C-   \n",
       "2              AK       Scottstad     114 Jones Garden          D-      D-   \n",
       "\n",
       "Category    Services          \n",
       "Subcategory   Police Schools  \n",
       "0                 A+       C  \n",
       "1                  D      B+  \n",
       "2                  D       D  "
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th>Category</th>\n",
       "      <th>State</th>\n",
       "      <th>Street</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Subcategory</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>City</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Rowlandchester</th>\n",
       "      <td>AK</td>\n",
       "      <td>386 Rebecca Cove</td>\n",
       "      <td>C-</td>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Scottstad</th>\n",
       "      <td>AK</td>\n",
       "      <td>082 Leblanc Freeway</td>\n",
       "      <td>D</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Scottstad</th>\n",
       "      <td>AK</td>\n",
       "      <td>114 Jones Garden</td>\n",
       "      <td>D-</td>\n",
       "      <td>D-</td>\n",
       "      <td>D</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stevenshire</th>\n",
       "      <td>AK</td>\n",
       "      <td>238 Andrew Rue</td>\n",
       "      <td>D-</td>\n",
       "      <td>A</td>\n",
       "      <td>A-</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Clarkland</th>\n",
       "      <td>AL</td>\n",
       "      <td>430 Douglas Mission</td>\n",
       "      <td>A</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category       State               Street     Culture         Services        \n",
       "Subcategory                               Restaurants Museums   Police Schools\n",
       "City                                                                          \n",
       "Rowlandchester    AK     386 Rebecca Cove          C-      A-       A+       C\n",
       "Scottstad         AK  082 Leblanc Freeway           D      C-        D      B+\n",
       "Scottstad         AK     114 Jones Garden          D-      D-        D       D\n",
       "Stevenshire       AK       238 Andrew Rue          D-       A       A-      A-\n",
       "Clarkland         AL  430 Douglas Mission           A       F       C+      B+"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.set_index(keys = \"City\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th>Category</th>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th>Street</th>\n",
       "      <th>Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Subcategory</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(Culture, Museums)</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A-</th>\n",
       "      <td>AK</td>\n",
       "      <td>Rowlandchester</td>\n",
       "      <td>386 Rebecca Cove</td>\n",
       "      <td>C-</td>\n",
       "      <td>A+</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C-</th>\n",
       "      <td>AK</td>\n",
       "      <td>Scottstad</td>\n",
       "      <td>082 Leblanc Freeway</td>\n",
       "      <td>D</td>\n",
       "      <td>D</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D-</th>\n",
       "      <td>AK</td>\n",
       "      <td>Scottstad</td>\n",
       "      <td>114 Jones Garden</td>\n",
       "      <td>D-</td>\n",
       "      <td>D</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>AK</td>\n",
       "      <td>Stevenshire</td>\n",
       "      <td>238 Andrew Rue</td>\n",
       "      <td>D-</td>\n",
       "      <td>A-</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>AL</td>\n",
       "      <td>Clarkland</td>\n",
       "      <td>430 Douglas Mission</td>\n",
       "      <td>A</td>\n",
       "      <td>C+</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category           State            City               Street     Culture  \\\n",
       "Subcategory                                                   Restaurants   \n",
       "(Culture, Museums)                                                          \n",
       "A-                    AK  Rowlandchester     386 Rebecca Cove          C-   \n",
       "C-                    AK       Scottstad  082 Leblanc Freeway           D   \n",
       "D-                    AK       Scottstad     114 Jones Garden          D-   \n",
       "A                     AK     Stevenshire       238 Andrew Rue          D-   \n",
       "F                     AL       Clarkland  430 Douglas Mission           A   \n",
       "\n",
       "Category           Services          \n",
       "Subcategory          Police Schools  \n",
       "(Culture, Museums)                   \n",
       "A-                       A+       C  \n",
       "C-                        D      B+  \n",
       "D-                        D       D  \n",
       "A                        A-      A-  \n",
       "F                        C+      B+  "
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.set_index(keys = (\"Culture\", \"Museums\")).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th>Street</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Culture</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Services</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>Subcategory</th>\n",
       "      <th></th>\n",
       "      <th>Restaurants</th>\n",
       "      <th>Museums</th>\n",
       "      <th>Police</th>\n",
       "      <th>Schools</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th>City</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">AK</th>\n",
       "      <th>Rowlandchester</th>\n",
       "      <td>386 Rebecca Cove</td>\n",
       "      <td>C-</td>\n",
       "      <td>A-</td>\n",
       "      <td>A+</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Scottstad</th>\n",
       "      <td>082 Leblanc Freeway</td>\n",
       "      <td>D</td>\n",
       "      <td>C-</td>\n",
       "      <td>D</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Scottstad</th>\n",
       "      <td>114 Jones Garden</td>\n",
       "      <td>D-</td>\n",
       "      <td>D-</td>\n",
       "      <td>D</td>\n",
       "      <td>D</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stevenshire</th>\n",
       "      <td>238 Andrew Rue</td>\n",
       "      <td>D-</td>\n",
       "      <td>A</td>\n",
       "      <td>A-</td>\n",
       "      <td>A-</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AL</th>\n",
       "      <th>Clarkland</th>\n",
       "      <td>430 Douglas Mission</td>\n",
       "      <td>A</td>\n",
       "      <td>F</td>\n",
       "      <td>C+</td>\n",
       "      <td>B+</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Category                           Street     Culture         Services        \n",
       "Subcategory                               Restaurants Museums   Police Schools\n",
       "State City                                                                    \n",
       "AK    Rowlandchester     386 Rebecca Cove          C-      A-       A+       C\n",
       "      Scottstad       082 Leblanc Freeway           D      C-        D      B+\n",
       "      Scottstad          114 Jones Garden          D-      D-        D       D\n",
       "      Stevenshire          238 Andrew Rue          D-       A       A-      A-\n",
       "AL    Clarkland       430 Douglas Mission           A       F       C+      B+"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "neighborhoods.set_index(keys = [\"State\", \"City\"]).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.7 Coding Challenge"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 7.7.1 Problems"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Market</th>\n",
       "      <th>Status</th>\n",
       "      <th>State</th>\n",
       "      <th>Funding Rounds</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>#waywire</td>\n",
       "      <td>News</td>\n",
       "      <td>Acquired</td>\n",
       "      <td>NY</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>&amp;TV Communications</td>\n",
       "      <td>Games</td>\n",
       "      <td>Operating</td>\n",
       "      <td>CA</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-R- Ranch and Mine</td>\n",
       "      <td>Tourism</td>\n",
       "      <td>Operating</td>\n",
       "      <td>TX</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>004 Technologies</td>\n",
       "      <td>Software</td>\n",
       "      <td>Operating</td>\n",
       "      <td>IL</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1-4 All</td>\n",
       "      <td>Software</td>\n",
       "      <td>Operating</td>\n",
       "      <td>NC</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Name    Market     Status State  Funding Rounds\n",
       "0            #waywire      News   Acquired    NY               1\n",
       "1  &TV Communications     Games  Operating    CA               2\n",
       "2  -R- Ranch and Mine   Tourism  Operating    TX               2\n",
       "3    004 Technologies  Software  Operating    IL               1\n",
       "4             1-4 All  Software  Operating    NC               1"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "investments = pd.read_csv(\"investments.csv\")\n",
    "investments.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name              27763\n",
       "Market              693\n",
       "Status                3\n",
       "State                61\n",
       "Funding Rounds       16\n",
       "dtype: int64"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "investments.nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "investments = investments.set_index(\n",
    "    keys = [\"Status\", \"Funding Rounds\", \"State\"]\n",
    ").sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Market</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Status</th>\n",
       "      <th>Funding Rounds</th>\n",
       "      <th>State</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">Acquired</th>\n",
       "      <th rowspan=\"5\" valign=\"top\">1</th>\n",
       "      <th>AB</th>\n",
       "      <td>Hallpass Media</td>\n",
       "      <td>Games</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AL</th>\n",
       "      <td>EnteGreat</td>\n",
       "      <td>Enterprise Software</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AL</th>\n",
       "      <td>Onward Behavioral Health</td>\n",
       "      <td>Biotechnology</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AL</th>\n",
       "      <td>Proxsys</td>\n",
       "      <td>Biotechnology</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AZ</th>\n",
       "      <td>Envox Group</td>\n",
       "      <td>Public Relations</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   Name               Market\n",
       "Status   Funding Rounds State                                               \n",
       "Acquired 1              AB               Hallpass Media                Games\n",
       "                        AL                    EnteGreat  Enterprise Software\n",
       "                        AL     Onward Behavioral Health        Biotechnology\n",
       "                        AL                      Proxsys        Biotechnology\n",
       "                        AZ                  Envox Group     Public Relations"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "investments.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 7.7.2 Solutions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Market</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Funding Rounds</th>\n",
       "      <th>State</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">1</th>\n",
       "      <th>AB</th>\n",
       "      <td>Cardinal Media Technologies</td>\n",
       "      <td>Social Network Media</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AB</th>\n",
       "      <td>Easy Bill Online</td>\n",
       "      <td>Tracking</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AB</th>\n",
       "      <td>Globel Direct</td>\n",
       "      <td>Public Relations</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AB</th>\n",
       "      <td>Ph03nix New Media</td>\n",
       "      <td>Games</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AL</th>\n",
       "      <td>Naubo</td>\n",
       "      <td>News</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                             Name                Market\n",
       "Funding Rounds State                                                   \n",
       "1              AB     Cardinal Media Technologies  Social Network Media\n",
       "               AB                Easy Bill Online              Tracking\n",
       "               AB                   Globel Direct      Public Relations\n",
       "               AB               Ph03nix New Media                 Games\n",
       "               AL                           Naubo                  News"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "investments.loc[(\"Closed\",)].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Market</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>NY</th>\n",
       "      <td>Genesis Networks</td>\n",
       "      <td>Web Hosting</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TX</th>\n",
       "      <td>ACTIVE Network</td>\n",
       "      <td>Software</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   Name       Market\n",
       "State                               \n",
       "NY     Genesis Networks  Web Hosting\n",
       "TX       ACTIVE Network     Software"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "investments.loc[(\"Acquired\", 10)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Market</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Status</th>\n",
       "      <th>Funding Rounds</th>\n",
       "      <th>State</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">Operating</th>\n",
       "      <th rowspan=\"4\" valign=\"top\">6</th>\n",
       "      <th>NJ</th>\n",
       "      <td>Agile Therapeutics</td>\n",
       "      <td>Biotechnology</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>NJ</th>\n",
       "      <td>Agilence</td>\n",
       "      <td>Retail Technology</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>NJ</th>\n",
       "      <td>Edge Therapeutics</td>\n",
       "      <td>Biotechnology</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>NJ</th>\n",
       "      <td>Nistica</td>\n",
       "      <td>Web Hosting</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                              Name             Market\n",
       "Status    Funding Rounds State                                       \n",
       "Operating 6              NJ     Agile Therapeutics      Biotechnology\n",
       "                         NJ               Agilence  Retail Technology\n",
       "                         NJ      Edge Therapeutics      Biotechnology\n",
       "                         NJ                Nistica        Web Hosting"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "investments.loc[(\"Operating\", 6, \"NJ\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>State</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>CA</th>\n",
       "      <td>CipherMax</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CA</th>\n",
       "      <td>Dilithium Networks</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CA</th>\n",
       "      <td>Moblyng</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CA</th>\n",
       "      <td>SolFocus</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CA</th>\n",
       "      <td>Solyndra</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>FL</th>\n",
       "      <td>Extreme Enterprises</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GA</th>\n",
       "      <td>MedShape</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>NC</th>\n",
       "      <td>Biolex Therapeutics</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WA</th>\n",
       "      <td>Cozi Group</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      Name\n",
       "State                     \n",
       "CA               CipherMax\n",
       "CA      Dilithium Networks\n",
       "CA                 Moblyng\n",
       "CA                SolFocus\n",
       "CA                Solyndra\n",
       "FL     Extreme Enterprises\n",
       "GA                MedShape\n",
       "NC     Biolex Therapeutics\n",
       "WA              Cozi Group"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "investments.loc[(\"Closed\", 8), (\"Name\",)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Market</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Status</th>\n",
       "      <th>Funding Rounds</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">Acquired</th>\n",
       "      <th>1</th>\n",
       "      <td>AkaRx</td>\n",
       "      <td>Biotechnology</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Aptalis Pharma</td>\n",
       "      <td>Biotechnology</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Cadent</td>\n",
       "      <td>Software</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Cancer Genetics</td>\n",
       "      <td>Health And Wellness</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Clacendix</td>\n",
       "      <td>E-Commerce</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    Name               Market\n",
       "Status   Funding Rounds                                      \n",
       "Acquired 1                         AkaRx        Biotechnology\n",
       "         1                Aptalis Pharma        Biotechnology\n",
       "         1                        Cadent             Software\n",
       "         1               Cancer Genetics  Health And Wellness\n",
       "         1                     Clacendix           E-Commerce"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "investments.xs(key = \"NJ\", level = 2).head()\n",
    "investments.xs(key = \"NJ\", level = \"State\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Status</th>\n",
       "      <th>Funding Rounds</th>\n",
       "      <th>State</th>\n",
       "      <th>Name</th>\n",
       "      <th>Market</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Acquired</td>\n",
       "      <td>1</td>\n",
       "      <td>AB</td>\n",
       "      <td>Hallpass Media</td>\n",
       "      <td>Games</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Acquired</td>\n",
       "      <td>1</td>\n",
       "      <td>AL</td>\n",
       "      <td>EnteGreat</td>\n",
       "      <td>Enterprise Software</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Acquired</td>\n",
       "      <td>1</td>\n",
       "      <td>AL</td>\n",
       "      <td>Onward Behavioral Health</td>\n",
       "      <td>Biotechnology</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Acquired</td>\n",
       "      <td>1</td>\n",
       "      <td>AL</td>\n",
       "      <td>Proxsys</td>\n",
       "      <td>Biotechnology</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Acquired</td>\n",
       "      <td>1</td>\n",
       "      <td>AZ</td>\n",
       "      <td>Envox Group</td>\n",
       "      <td>Public Relations</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Status  Funding Rounds State                      Name  \\\n",
       "0  Acquired               1    AB            Hallpass Media   \n",
       "1  Acquired               1    AL                 EnteGreat   \n",
       "2  Acquired               1    AL  Onward Behavioral Health   \n",
       "3  Acquired               1    AL                   Proxsys   \n",
       "4  Acquired               1    AZ               Envox Group   \n",
       "\n",
       "                Market  \n",
       "0                Games  \n",
       "1  Enterprise Software  \n",
       "2        Biotechnology  \n",
       "3        Biotechnology  \n",
       "4     Public Relations  "
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "investments = investments.reset_index()\n",
    "investments.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.8 Summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
